Skip to content

Remove any references to fxa migration status from users app #6596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions kitsune/messages/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def create_suggestion(item):

suggestions = []
user_criteria = Q(username__istartswith=pre) | Q(profile__name__istartswith=pre)
users = User.objects.filter(
user_criteria, is_active=True, profile__is_fxa_migrated=True
).select_related("profile")[:10]
users = User.objects.filter(user_criteria, is_active=True).select_related("profile")[:10]

for user in users:
suggestions.append(create_suggestion(user))
Expand Down
3 changes: 1 addition & 2 deletions kitsune/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ProfileAdmin(admin.ModelAdmin):
"name",
"public_email",
"bio",
"is_fxa_migrated",
"fxa_uid",
"fxa_refresh_token",
"zendesk_id",
Expand Down Expand Up @@ -76,7 +75,7 @@ class ProfileAdmin(admin.ModelAdmin):
form = ProfileAdminForm
list_display = ["full_user", "name", "get_products"]
list_select_related = True
list_filter = ["is_fxa_migrated", "country"]
list_filter = ["country"]
search_fields = ["user__username", "user__email", "name", "fxa_uid"]
autocomplete_fields = ["user"]
readonly_fields = ["fxa_refresh_token", "zendesk_id"]
Expand Down
1 change: 0 additions & 1 deletion kitsune/users/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def usernames(request):

users = (
User.objects.filter(is_active=True)
.exclude(profile__is_fxa_migrated=False)
.filter(Q(username__istartswith=pre) | Q(profile__name__istartswith=pre))
.select_related("profile")
)[:10]
Expand Down
5 changes: 1 addition & 4 deletions kitsune/users/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def create_user(self, claims):
# Create a user profile for the user and populate it with data from
# Mozilla accounts
profile, created = Profile.objects.get_or_create(user=user)
profile.is_fxa_migrated = True
profile.fxa_uid = claims.get("uid")
profile.fxa_avatar = claims.get("avatar", "")
profile.name = claims.get("displayName", "")
Expand Down Expand Up @@ -197,15 +196,13 @@ def update_user(self, user, claims):
# Check if the user has active subscriptions
subscriptions = claims.get("subscriptions", [])

if (request := getattr(self, "request", None)) and not profile.is_fxa_migrated:
if request := getattr(self, "request", None):
# Check if there is already a Mozilla account with this ID
if Profile.objects.filter(fxa_uid=fxa_uid).exists():
msg = _("This Mozilla account is already used in another profile.")
messages.error(request, msg)
return None

# If it's not migrated, we can assume that there isn't an FxA id too
profile.is_fxa_migrated = True
profile.fxa_uid = fxa_uid
# This is the first time an existing user is using FxA. Redirect to profile edit
# in case the user wants to update any settings.
Expand Down
2 changes: 1 addition & 1 deletion kitsune/users/jinja2/users/edit_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

{% block content %}
<article id="edit-profile">
{% if profile and profile.is_fxa_migrated and request.user == profile.user %}
{% if profile and request.user == profile.user %}
<h1 class="sumo-page-heading">{{ _('Your Account') }}</h1>
<p class="mb-0"><strong>{{ user.email }}</strong></p>
<p>
Expand Down
2 changes: 1 addition & 1 deletion kitsune/users/jinja2/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{% block breadcrumbs %}{% endblock %}
{% block content %}
<article id="profile">
{% if is_owner and profile.is_fxa_migrated %}
{% if is_owner %}
<h1 class="sumo-page-heading">{{ _('Your Account') }}</h1>
<p class="mb-0"><strong>{{ user.email }}</strong></p>
<p>
Expand Down
17 changes: 17 additions & 0 deletions kitsune/users/migrations/0034_remove_is_fxa_migrated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.20 on 2025-03-27 11:11

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("users", "0033_delete_old_account_events"),
]

operations = [
migrations.RemoveField(
model_name="profile",
name="is_fxa_migrated",
),
]
2 changes: 0 additions & 2 deletions kitsune/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class AccountType(models.TextChoices):
blank=True,
verbose_name=_lazy("When the user was sent a community " "health survey"),
)
is_fxa_migrated = models.BooleanField(default=False)
fxa_uid = models.CharField(blank=True, null=True, unique=True, max_length=128)
fxa_avatar = models.URLField(max_length=512, blank=True, default="")
products = models.ManyToManyField(Product, related_name="subscribed_users")
Expand Down Expand Up @@ -198,7 +197,6 @@ def clear(self):
self.people_mozilla_org = ""
self.matrix_handle = ""
self.city = ""
self.is_fxa_migrated = False
self.fxa_uid = ""

@property
Expand Down
1 change: 0 additions & 1 deletion kitsune/users/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Meta:
country = "US"
city = "Portland"
locale = "en-US"
is_fxa_migrated = True
user = factory.SubFactory(UserFactory, profile=None)


Expand Down
23 changes: 0 additions & 23 deletions kitsune/users/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ def test_username_already_exists(self, message_mock):
self.assertEqual(user.username, "bar1")
message_mock.success.assert_called()

def test_login_fxa_uid_missing(self):
"""Test user filtering without FxA uid."""
claims = {
"uid": "",
}

request_mock = Mock(spec=HttpRequest)
self.backend.claims = claims
self.backend.request = request_mock
assert not self.backend.filter_users_by_claims(claims)

def test_login_existing_user_by_fxa_uid(self):
"""Test user filtering by FxA uid."""
user = UserFactory.create(profile__fxa_uid="my_unique_fxa_id")
Expand All @@ -125,17 +114,13 @@ def test_connecting_using_existing_fxa_account(self, message_mock):
"""Test connecting a SUMO account with an existing FxA in SUMO."""
UserFactory.create(profile__fxa_uid="my_unique_fxa_id")
user = UserFactory.create()
user.profile.is_fxa_migrated = False
user.profile.save()
claims = {
"uid": "my_unique_fxa_id",
}
# Test without a request (for example, when called from a Celery task).
with self.subTest("without a request"):
self.backend.update_user(user, claims)
assert not message_mock.error.called
assert not User.objects.get(id=user.id).profile.is_fxa_migrated
assert not User.objects.get(id=user.id).profile.fxa_uid
# Test with a request.
request_mock = Mock(spec=HttpRequest)
request_mock.session = {}
Expand All @@ -145,8 +130,6 @@ def test_connecting_using_existing_fxa_account(self, message_mock):
message_mock.error.assert_called_with(
request_mock, "This Mozilla account is already used in another profile."
)
assert not User.objects.get(id=user.id).profile.is_fxa_migrated
assert not User.objects.get(id=user.id).profile.fxa_uid

def test_login_existing_user_by_email(self):
"""Test user filtering by email."""
Expand All @@ -170,7 +153,6 @@ def test_email_changed_in_FxA_match_by_uid(self, message_mock):
user = UserFactory.create(
profile__fxa_uid="my_unique_fxa_id",
email="foo@example.com",
profile__is_fxa_migrated=True,
)
claims = {"uid": "my_unique_fxa_id", "email": "bar@example.com", "subscriptions": "[]"}
self.backend.update_user(user, claims)
Expand All @@ -183,12 +165,9 @@ def test_email_changed_in_FxA_match_by_uid(self, message_mock):
@patch("mozilla_django_oidc.auth.OIDCAuthenticationBackend.verify_token")
def test_link_sumo_account_fxa(self, verify_token_mock, requests_mock, message_mock):
"""Test that an existing SUMO account is succesfully linked to Mozilla account."""

verify_token_mock.return_value = True

user = UserFactory.create(email="sumo@example.com", profile__name="Kenny Bania")
user.profile.is_fxa_migrated = False
user.profile.save()
auth_request = RequestFactory().get("/foo", {"code": "foo", "state": "bar"})
auth_request.session = {}
auth_request.user = user
Expand All @@ -213,8 +192,6 @@ def test_link_sumo_account_fxa(self, verify_token_mock, requests_mock, message_m
requests_mock.post.return_value = post_json_mock

self.backend.authenticate(auth_request)
assert user.profile.is_fxa_migrated
self.assertEqual(user.profile.fxa_uid, "my_unique_fxa_id")
self.assertEqual(user.email, "fxa@example.com")
self.assertEqual(user.profile.name, "Kenny Bania")
message_mock.info.assert_called_with(auth_request, "fxa_notification_updated")
Expand Down